package cn.itcast.zt.java8.model.proxy.self;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 创建代理类,实现对开关的判断(这里是通过聚合的方式实现的也可以用继承的方式)
 * create by zhangtian105 on 2021/9/15
 */
public class SwitchFunctionProxy extends SwitchFunction {
    private ISwitchFunction switchFunction;

    SwitchFunctionProxy(ISwitchFunction switchFunction) {
        this.switchFunction = switchFunction;
    }

    @Override
    public Object run(Method method, Object obj, Object... arg) throws InvocationTargetException, IllegalAccessException {
        System.out.println("****  代理执行:开关判断  ***");
        Boolean flag = true;

        if (flag) {
            return super.run(method, obj, arg);
        }

        return null;
    }
}
